import java.awt.Frame;
import java.awt.event.WindowEvent;
import java.awt.event.WindowAdapter;


import javax.media.opengl.*;
import javax.media.opengl.awt.GLCanvas;
import com.jogamp.opengl.util.*;



public class JoglTest2 implements GLEventListener
{
	private double theta = 0;
	private double s = 0;
	private double c = 0;
	
	
	/**
	 * @param args
	 */
	public static void main(String[] args) 
	{
		GLProfile glp = GLProfile.getDefault();
		GLCapabilities caps = new GLCapabilities(glp);
		GLCanvas canvas = new GLCanvas(caps);
		
		Frame frame = new Frame("JoglTest2");
		frame.setSize(300, 300);
		frame.add(canvas);
		frame.setVisible(true);
		
		frame.addWindowListener(new WindowAdapter(){
			public void windowClosing(WindowEvent e) {
				System.exit(0);
			}
		});
		
		canvas.addGLEventListener(new JoglTest2());
		
		FPSAnimator animator = new FPSAnimator(canvas, 60);
		animator.add(canvas);
		animator.start();
			
	}

	@Override
	public void display(GLAutoDrawable drawable)
	{
		update();
		render(drawable);
	}

	@Override
	public void dispose(GLAutoDrawable arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void init(GLAutoDrawable arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void reshape(GLAutoDrawable arg0, int arg1, int arg2, int arg3,
			int arg4) {
		// TODO Auto-generated method stub
		
	}
	private void update()
	{
		theta += 0.01;
		s = Math.sin(theta);
		c = Math.cos(theta);
	}
	
	private void render(GLAutoDrawable drawable)
	{
		GL2 gl = drawable.getGL().getGL2();
		
		gl.glClear(GL.GL_COLOR_BUFFER_BIT);
			
		//DRAW A TRIANGLE
		gl.glBegin(GL.GL_TRIANGLES);
		gl.glColor3f(1,0,0);
		gl.glVertex2d(-c, -c);
		gl.glColor3f(0,1,0);
		gl.glVertex2d(0, -c);
		gl.glColor3f(0,0,1);
		gl.glVertex2d(s, -s);
		gl.glEnd();
		
		//Draw a sphere
	}

}
